﻿using System;
using System.Collections.Generic;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    internal class CRNRecord : BiffRecord
    {
        List<SerAr>crnOper = new List<SerAr>();
        private byte colLast;
        private byte colFirst;
        private ushort row;

        protected override void ReadContent(BiffReaderContext context, int length)
        {
            this.colLast = context.ReadByte();
            this.colFirst = context.ReadByte();
            this.row = context.ReadUInt16();
            int count = colLast - colFirst + 1;
            for (int i = 0; i < count; i++)
            {
                SerAr serAr = SerAr.Read(context.Reader);
                this.crnOper.Add(serAr);
            }
        }

        internal override BiffRecordType RecordType
        {
            get { return BiffRecordType.CRN; }
        }

        internal override void WriteContent(BiffWriterWorkbookContext context)
        {
            context.Write(this.colLast);
            context.Write(this.colFirst);
            context.Write(this.row);
            foreach (var item in this.crnOper)
                item.Write(context.Writer);

        }
    }
}